package com.xucan.anno.mainx;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class MjaoyB {
    public static void main(String[] args) throws Exception{
        testFieldAnno();

    }
    public static  void  testFieldAnno()throws Exception{
        User user = new User();
        Field field = user.getClass().getDeclaredField("name");
        field.setAccessible(true);
        if (field.isAnnotationPresent(TestAnno.class)) {
            TestAnno annotation = field.getAnnotation(TestAnno.class);
            System.out.println(annotation.values());//chaoshen
        }
    }
    public static  void testMethodAnno()throws Exception{
        User user = new User();
        Method method = user.getClass().getDeclaredMethod("say");
        if (method.isAnnotationPresent(TestAnno.class)) {
            TestAnno annotation = method.getAnnotation(TestAnno.class);
            System.out.println(annotation.values());//hello
        }
    }


    private static void extracted() {
        User user = new User();
        boolean annotationPresent = user.getClass().isAnnotationPresent(TestAnno.class);
        if (annotationPresent) {
            TestAnno annotation = user.getClass().getAnnotation(TestAnno.class);
            System.out.println(annotation.values());//hello
        }
    }
}
